package lch.jobs;

import lch.constant.RedisConstant;
import lch.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author lch
 * @date 2019-12-22 21:10
 */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg() {
        //获取相差集合，获取垃圾图片集合
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (set != null) {
            for (String s : set) {
                //删除七牛云中垃圾图片
                QiniuUtils.deleteFileFromQiniu(s);
                //删除大集合中的垃圾图片
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, s);
            }
        }
    }
}
